---
title: "Dashboard"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
source: embed
---
```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse)
library(plotly)
library(p8105.datasets)
data("instacart")
instacart =
instacart %>%
as_tibble(instacart)
```
Column {data-width=350}
-----------------------------------------------------------------------
### Number Of Each Kind Of Products Ordered In Fresh Fruits Aisle Over A Day
```{r}
instacart %>%
filter(aisle == "fresh fruits") %>%
group_by(order_hour_of_day, product_name) %>%
summarize(n = n()) %>%
mutate(text_label = str_c("Product name: ", product_name)) %>%
plot_ly(
x = ~order_hour_of_day, y = ~n, type = "scatter", mode = "markers",
color = ~product_name, text = ~text_label, alpha = 0.6, height = 700) %>%
layout(legend = list(x = -0.1, y = -2)) %>%
layout(xaxis = list(title = 'Order Hour Of A Day'),
yaxis = list(title = 'Number'))
```
Column {data-width=350}
-----------------------------------------------------------------------
### Days Since Prior Order Of Each Aisle In Snacks Department
```{r }
instacart %>%
filter(reordered == 1) %>%
filter(department == "snacks") %>%
mutate(aisle = fct_reorder(aisle, days_since_prior_order)) %>%
plot_ly(y = ~days_since_prior_order, color = ~aisle, type = "box", colors = "viridis") %>%
layout(yaxis = list(title = "Days Since Prior Order"))
```
### Number Of Every Kind Of Product Ordered In Milk Aisle (At Least 500 Orderd)
```{r}
instacart %>%
filter(aisle == "milk") %>%
group_by(aisle, product_name) %>%
summarize(n = n()) %>%
filter(n >= 500) %>%
mutate(product_name = fct_reorder(product_name, n)) %>%
mutate(text_label = str_c("Aisle: ", aisle)) %>%
plot_ly(x = ~product_name, y = ~n, color = ~product_name, text = ~text_label, type = "bar", colors = "viridis") %>%
layout(showlegend = FALSE) %>%
layout(xaxis = list(title = list(text = "Product", standoff = 5)), yaxis = list(title = "Number"))
```